import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.Constructor;
import java.math.BigDecimal;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class MyInteger {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException {
        Integer integer = 12;

        System.out.println(integer);

        int i = new Integer(4);

        System.out.println(i);

        Class clazz = Class.forName("com.wx.reflect.example1.Student");
        Class[] parameterType = null;
        Constructor constructor = clazz.getConstructor(parameterType);
    }


}

class FindNumber {
    public static void main(String[] args) {
        //定义数组
        int[] a = {23, 78, 12, 45, 11, 99};

        Scanner sc = new Scanner(System.in);
        System.out.println("输入查找的数字(整数)：");
        int num = sc.nextInt();

        int flag = -1;

        for (int i = 0; i < a.length; i++) {
            if (a[i] == num) {
                flag = i;
                break;
            }
        }
        if (flag == -1) {
            System.out.println("没有这个数字");
        } else {
            System.out.println(num + "在数组的第" + flag + "个位置");
        }
    }
}

class Test {
    /*public static void main(String[] args) {
        int[] arr = {431,54,25,25,26,45,2,4,65,3,64,6,46,7,54};
        //排序
        Arrays.sort(arr);
        //打印
        System.out.println(Arrays.toString(arr));

        //查询元素2
        int i = Arrays.binarySearch(arr, 2);
        System.out.println("元素2在数组中的索引是:"+i);

        //查询元素200
        int i2 = Arrays.binarySearch(arr, 200);
        System.out.println("元素200在数组中的索引是:"+i2);


        Scanner sc = new Scanner(System.in);
        System.out.println("请输入年龄和身高:(年龄是整数,身高是小数,中间使用逗号分隔)");
        String s = sc.next();
        String[] arr1 = s.split(",");

        //0索引是年龄,1索引是身高
        int i1 = Integer.parseInt(arr1[0]);
        double v = Double.parseDouble(arr1[1]);

        System.out.println("转成整数后的年龄是:"+i1);
        System.out.println("转成小数后的身高是:"+v);
    }*/

    public static void main(String[] args) {
        double[] arr = {0.1, 0.2, 2.1, 3.2, 5.56, 7.21};
        BigDecimal sum = new BigDecimal(0);//移情别恋
        System.out.println(sum);
        for (int i = 0; i < arr.length; i++) {
            BigDecimal bd = new BigDecimal(arr[i] + "");
            sum = sum.add(bd);
        }
        BigDecimal bd2 = new BigDecimal(arr.length + "");
        BigDecimal avg = sum.divide(bd2, 2, BigDecimal.ROUND_HALF_UP);
        System.out.println("数组的平均值是:" + avg);
    }
}


class ObjectStreamExample {
    public static void main(String[] args) {
        // Writing object to a file
        try {
            FileOutputStream fos = new FileOutputStream("object.text");
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(new MyObject("sss", 44));
            oos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        // Reading object from a file
        try {
            FileInputStream fis = new FileInputStream("object.text");
            ObjectInputStream ois = new ObjectInputStream(fis);
            MyObject obj = (MyObject) ois.readObject();
            System.out.println(obj);
            ois.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

class MyObject implements java.io.Serializable {
    // Your code goes here
    private String name;
    private int age;

    public MyObject(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "MyObject{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
class UdpServer {
    public static void main(String[] args) throws Exception {
        // 服务端接收客户端发送的数据报
        DatagramSocket socket = new DatagramSocket(8888);
        byte[] buf = new byte[1024];
        DatagramPacket packet = new DatagramPacket(buf, buf.length);
        socket.receive(packet);
        String info = new String(buf, 0, packet.getLength());
        System.out.println("客户端发送的信息：" + info);

        // 服务端发送数据报给客户端
        InetAddress address = packet.getAddress();
        int port = packet.getPort();
        byte[] data2 = "欢迎你！".getBytes();
        DatagramPacket packet2 = new DatagramPacket(data2, data2.length, address, port);
        socket.send(packet2);
        socket.close();
    }
}
class UDPClient {
    public static void main(String[] args) throws Exception {
        // 创建UDP套接字
        DatagramSocket socket = new DatagramSocket();
        // 将要发送的数据转换为字节数组
        String message = "Hello, Server";
        byte[] sendBuf = message.getBytes();
        // 将IP地址和端口号包装成SocketAddress
        InetAddress addr = InetAddress.getByName("127.0.0.1");
        int port = 8888;
        DatagramPacket sendPacket = new DatagramPacket(sendBuf, sendBuf.length, addr, port);
        // 发送数据
        socket.send(sendPacket);

        // 接收数据
        byte[] recvBuf = new byte[100];
        DatagramPacket recvPacket = new DatagramPacket(recvBuf, recvBuf.length);
        socket.receive(recvPacket);
        String recvStr = new String(recvPacket.getData(), 0, recvPacket.getLength());
        System.out.println("收到:" + recvStr);

        socket.close();
    }
}


class MyArray{
    public static void main(String[] args) {
        int i = new Scanner(System.in).nextInt();
        int [] arr = new int[i];
        Random random = new Random();
        for (int j = 0; j < i; j++) {
            arr[j] = random.nextInt(10);
        }
        System.out.println(Arrays.toString(arr));
    }
}






